//
//  SecondViewController.m
//  王宇先_09
//
//  Created by wyx on 16/3/23.
//  Copyright © 2016年 Apon. All rights reserved.
//

#import "SecondViewController.h"
#import "CellOfPic.h"
#import "TableViewOfPic.h"
#import "ModleOfPic.h"
#pragma mark - 声明 协议
@interface SecondViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, retain) TableViewOfPic *tableViewOfSecond;
@property (nonatomic, retain) NSMutableArray *arrOfPic;
@end

@implementation SecondViewController
#pragma mark - dealloc
-(void)dealloc{
    [_tableViewOfSecond release];
    [_arrOfPic release];
    [super dealloc];
}
#pragma mark - 加载
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.navigationItem.title = @"图片";
    [self createTableView];
    [self handleDate2];
    
}
#pragma mark - Date
-(void)handleDate2{

    self.arrOfPic = [[NSMutableArray alloc] init];
    for (int i = 1; i < 5; i++) {
        NSString *name = [NSString stringWithFormat:@"%d.jpg",i];
        UIImageView *image =  [[UIImageView alloc] initWithImage:[UIImage imageNamed:name]];
        [self.arrOfPic addObject:image];
        [image release];
    }
    
}
#pragma mark - 创建 tableView
- (void)createTableView{
    self.tableViewOfSecond = [[TableViewOfPic alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStylePlain];
    [self.view addSubview:self.tableViewOfSecond];
    //指定代理人
    self.tableViewOfSecond.dataSource = self;
    self.tableViewOfSecond.delegate = self;
    self.tableViewOfSecond.separatorColor = [UIColor redColor];
    //注册 cell
    [self.tableViewOfSecond registerClass:[CellOfPic class] forCellReuseIdentifier:@"pool"];
    [self.tableViewOfSecond release];
    
    
}
#pragma mark - 行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 4;
}
#pragma mark - cell 赋值
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    CellOfPic *cell = [tableView dequeueReusableCellWithIdentifier:@"pool"];
    UIImageView *image = [self.arrOfPic objectAtIndex:indexPath.row];
    [cell setCellContentValueImage:image];
    //cell 选中风格
    cell.selectionStyle = UITableViewCellEditingStyleNone;
    return cell;
}
#pragma mark - 返回每一行高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    UIImageView *image = [self.arrOfPic objectAtIndex:indexPath.row];
    return [CellOfPic heightOfCellPic:image];
}
#pragma mark - 其他协议方法
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
